<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>登录</title>
<%@ include file="common/base.jsp" %>
<link href="${pageContext.request.contextPath}/static/css/page.css" rel="stylesheet" type="text/css"/>

<script type="text/javascript">
var flag = 0;

function sbt(){
	$("#loginNameCode").html("");
	$("#passwordCode").html("");
	$("#authImgCode").html("");
	if(!loginNameValidate()){
		return false;
	}
	if(!passwordValidate()){
		return false;
	}
	if(!authImgValidate()){
		return false;
	}
  	var postForm=document.getElementById("frm");
  	postForm.submit() ;   
}
function loginNameValidate(){
	var loginName = $("#loginName").val();
	$("#authImgCode").html("");
	if(loginName == null || loginName.length < 1 || loginName =="登录名"){
		$("#authImgCode").append("登录名不能为空");
		return false;
	}
	return true;
}

function passwordValidate(){
	var password = $("#password").val();
	$("#authImgCode").html("");
	if(password == null || password.length < 1 ){
		$("#authImgCode").append("登录密码不能为空");
		return false;
	}
	return true;
}

function authImgValidate(){
	var authCode = $("#authCode").val();
	$("#authImgCode").html("");
	if(authCode == null || authCode.length < 1 || authCode =="验证码"){
		$("#authImgCode").append("验证码不能为空");
		return false;
	}
	return true;
}

function rst(){
	$("#loginName").val("");
    $("#password").val("");
    $("#authCode").val("");
    $("#authCode").focus();
    $("#password").focus();
    $("#loginName").focus();
    $("#loginName").blur();
}


 
$(function() {
    $("#authCode-btn").click(function() { 
        $("#authCode-img").attr("src", '${pageContext.request.contextPath}/authCode?'+new Date().getTime());
    });
    
    $("#authCode-img").click(function() { 
        $("#authCode-img").attr("src", '${pageContext.request.contextPath}/authCode?'+new Date().getTime());
    });
    if($("#saveName").val() != ""){
    	$("#loginName").val($("#saveName").val());
    }
    // $("#password").val("登录密码");
});

document.onkeydown=function(event){ 
    e = event ? event :(window.event ? window.event : null); 
    if(e.keyCode==13){ 
       //执行的方法 
       sbt();
    } 
} 
</script>
</head>

<body style="background:#fff">
<div id="login">
    <!--head-->
    <!--head end-->
    <!--content-->
    <div class="loginWrap">
    <h1>兴宝爱车后台管理系统</h1>
    <form id="frm" name="frm" action="login" method="post"  >
        <h2>登录</h2>
        <ul>   
            <li>
            	<div class="textBox username">
                  <input type="hidden" id="saveName" name="saveName" value="${loginName}">
                  <input type="text" class="text" value="admin" id="loginName" name="loginName" />
                  <input type="hidden" id="userType"  name="userType" value="0">
                  <%-- <p id="loginNameCode" class="tip"></p> --%>
                </div>
            </li>
            <li>
            	<div class="textBox password">
                  <input type="text" class="text" value="登录密码" onfocus="$(this).hide().siblings().show().focus()"/>
                  <input type="password" id="password" name="password"  class="text" style="display:none; color:#333;" value="admin"
                  onBlur="if($(this).val()==''){$(this).hide().siblings().show().blur()}"/>
                  <!-- <p id="passwordCode" class="tip"></p> -->
                </div>
            </li>
            <li style="height:78px">
              <div class="textBox" style="width:160px; padding-left:14px; display:inline-block">
                  <input  maxLength="4" id="authCode" name="authCode" style="width:160px" type="text" class="text" value="验证码" 
                    onblur="authImgValidate();"/>
              </div>
              <img src="${pageContext.request.contextPath}/authCode" class="yzm" id="authCode-img" />
              <span class="refresh" id="authCode-btn"></span>
              <p class="tip" id="authImgCode">${auth_code}${name_pass}${other_code}</p>
            </li>
        </ul>
        <div class="button_wrap">
            <input type="button"  onclick="sbt();" value="登录">
            <input type="button" class="btn_gray"  onclick="rst();" value="重置">
        </div>
    </form>
    </div>
    <!--content-->
    <!--foot-->
    <div id="foot">
        <p>北京掌中彩信息科技有限公司  提供技术支持</p>
    </div>
    <!--foot-->
</div>

<script>
$(document).ready(function() {
	$(".loginWrap .text").focus(function(){
		$(this).parent(".textBox").css("border-color","#408ebc");
		if($(this).val() == this.defaultValue){
			$(this).val('').css('color','#333');		
		}
	})  
	$(".loginWrap .text").blur(function(){
		$(this).parent(".textBox").css("border-color","#d0d0d0");
		if($(this).val() == ""){
			$(this).val(this.defaultValue).css('color','#999');	
		}
	})  
});
</script>
</body>
</html>
